#! /bin/sh

cmd=$1

start()
{
    rm -f /dev/hello_chardev
    insmod hello_timer.ko || exit 1
    echo "[*] insmod hello_timer.ko complete"

    major=`awk '/hello_chardev/ {print $1}' /proc/devices`

    mknod -m 666 /dev/hello_chardev c $major 0
    echo "[*] mknod /dev/hello_chardev success, major=$major"
}

stop()
{
    rm -f /dev/hello_chardev
    echo "[*] remove /dev/hello_chardev complete"
    rmmod hello_timer || exit 1
    echo "[*] rmmod hello_chardev complete"
}

case "$cmd" in
    "start" )
        echo "[*] start"
        start
        ;;
    "stop" )
        echo "[*] stop"
        stop
        ;;
    "restart" )
        echo "[*] restart"
        stop
        start
        ;;
    *)
        echo "[*] default"
        stop
        start
        ;;
esac
        

